-
Notifications
You must be signed in to change notification settings - Fork 132
feat(query-db-collection): expose query state from QueryObserver #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(query-db-collection): expose query state from QueryObserver #712
Conversation
🦋 Changeset detectedLatest commit: e92c3f2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 77.6 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 2.89 kB ℹ️ View Unchanged
|
samwillis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking ok, but question on the api design
| /** | ||
| * Check if the query is currently fetching data (including background refetches). | ||
| * Returns true during both initial fetches and background refetches. | ||
| */ | ||
| isFetching: () => boolean | ||
| /** | ||
| * Check if the query is currently refetching data in the background. | ||
| * Returns true only during background refetches (not initial fetch). | ||
| */ | ||
| isRefetching: () => boolean | ||
| /** | ||
| * Check if the query is loading for the first time (no data yet). | ||
| * Returns true only during the initial fetch before any data is available. | ||
| */ | ||
| isLoading: () => boolean | ||
| /** | ||
| * Get the timestamp (in milliseconds since epoch) when the data was last successfully updated. | ||
| * Returns 0 if the query has never successfully fetched data. | ||
| */ | ||
| dataUpdatedAt: () => number | ||
| /** | ||
| * Get the current fetch status of the query. | ||
| * - 'fetching': Query is currently fetching | ||
| * - 'paused': Query is paused (e.g., network offline) | ||
| * - 'idle': Query is not fetching | ||
| */ | ||
| fetchStatus: () => `fetching` | `paused` | `idle` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want these to be getters rather than methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah — Claude was just copying the other util functions but TanStack Query & DB generally both use getters so let's do the change along with the other utils.
BREAKING CHANGE: Query state utilities are now accessed as properties instead of function calls, aligning with TanStack Query's API patterns for a more intuitive developer experience. Changed utilities: - lastError() → lastError - isError() → isError - errorCount() → errorCount - isFetching() → isFetching - isRefetching() → isRefetching - isLoading() → isLoading - dataUpdatedAt() → dataUpdatedAt - fetchStatus() → fetchStatus New features: - Exposes TanStack Query's QueryObserver state through utility getters - Enables "Last updated" UI patterns and background fetch indicators - Provides insight into sync behavior beyond error states Migration: Remove parentheses when accessing these properties Example: collection.utils.isFetching() → collection.utils.isFetching Resolves user request from Discord where status is always 'ready' after initial load, making it impossible to know if background refetches are happening. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
5902599 to
bd32d34
Compare
- Merged latest changes from origin/main - Resolved conflicts in query.ts: - Combined queryObserver reference storage with query state initialization - Made clearError async to match main branch changes - Fixed test file to use property access instead of function calls for getters - Note: Some test failures to be investigated - likely timing issues from merge
- Fixed type compatibility issues by using UtilsRecord as TUtils parameter in return types - Removed duplicate queryState initialization - Converted all test function calls to property access for getters - Ran prettier to format code - Reduced test failures from 15 to 13 Type errors: 0 remaining Test status: 13 failures (down from 15), 60 passing
|
Closed in favor of #742 |
Adds new utility methods to QueryCollectionUtils to expose TanStack Query's QueryObserver state, addressing user request for visibility into sync status:
New utils exposed:
This allows users to:
Resolves user request from Discord where status is always 'ready' after initial load, making it impossible to know if background refetches are happening.
🤖 Generated with Claude Code
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact